import React, { Component } from 'react';
import {registry} from '../api/user';

class Registry extends Component {
    state = {
        username:'',
        password:''
    }
    render() {
        let {username,password,code} = this.state;
        return (
            <div>
                用户名：<input type="text" value={username} name="username" onChange={this.change}></input>
                密码:<input type="text" value={password} name="password"  onChange={this.change}></input>
                <button onClick={this.registry}>注册</button>
            </div>
        );
    }
    //change
    change = (e) => {
        this.setState({
            [e.target.name]:e.target.value
        })
    }

    //注册
    registry = () => {
        let {username,password} = this.state;

        if(username && password){
            registry(this.state).then(res => {
                if(res.data.code === 1){
                    this.props.history.push('/login');  
                }
            })
        }else{
            console.log("参数有误")
        }
    }


}

export default Registry;